package sorocabaverdedatauploader;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConnectionSorocabaFactory {

    private Connection conn;
    private String usuario, senha;

    ConnectionSorocabaFactory() {
        this.conn = null;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public void connect() {
        try {
            this.conn = null;

            String url = "jdbc:postgresql://localhost:5431/SorocabaVerdeBD";
            String user = this.usuario;
            String key = this.senha;

            Class.forName("org.postgresql.Driver");

            this.conn = DriverManager.getConnection(url, user, key);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public Connection getConn(){
        return this.conn;
    }
    
    public void closeConn(){
        try {
            this.conn.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
